#!/bin/bash
domain="flyrain.ml"
echo -e "\033[32m\033[01m $1 \033[0m" "请输入websocket的路径"
read newpath
# cat > /etc/nginx/conf.d/default.conf<<-EOF
# server { 
#     listen       80;
#     server_name  $domain;
#     rewrite ^(.*)$  https://\$host\$1 permanent; 
# }
# server {
#    listen  443 ssl http2;
#    ssl_certificate       /etc/nginx/ssl/fullchain.cer;
#    ssl_certificate_key   /etc/nginx/ssl/$domain.key;
#    ssl_protocols         TLSv1.2 TLSv1.3;
#    ssl_ciphers           TLS13-AES-128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305;
#      ssl_session_cache shared:SSL:100m;
#      ssl_session_timeout 1h;

#     server_name $domain;
#     location / {
#         root /etc/nginx/html;
#         index index.php index.html index.htm;
#     }
# }
# EOF
#personal use
cat > /etc/nginx/conf.d/default.conf<<-EOF
server { 
    listen       80;
    server_name  $domain;
    rewrite ^(.*)$  https://\$host\$1 permanent; 
}
server {
    listen 443 ssl http2;
    server_name $domain;
    root /etc/nginx/html;
    index index.php index.html;
    ssl_certificate /etc/nginx/ssl/fullchain.cer; 
    ssl_certificate_key /etc/nginx/ssl/$domain.key;
    #TLS 版本控制
    # ssl_protocols   TLSv1.3;
    # ssl_ciphers     TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256;
    ssl_protocols         TLSv1.2 TLSv1.3;
    ssl_ciphers           TLS13-AES-128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305;
    ssl_prefer_server_ciphers   on;
    # 开启 1.3 0-RTT
    ssl_early_data  on;
    ssl_stapling on;
    ssl_stapling_verify on;
    #add_header Strict-Transport-Security "max-age=31536000";
    #access_log /var/log/nginx/access.log combined;
    location /$newpath {
        proxy_redirect off;
        proxy_pass http://127.0.0.1:11234; 
        proxy_http_version 1.1;
        proxy_set_header Upgrade \$http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host \$http_host;
    }
    location / {
       try_files \$uri \$uri/ /index.php?\$args;
    }
}
EOF

nginx -s reload
